﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Moki.Core
{
    public interface ICondition
    {
        bool Apply(object obj);
    }

    /// <summary>
    /// Encapsulates predicate function
    /// </summary>
    /// <typeparam name="T">Argument type</typeparam>
    public class Condition<T> : ICondition
    {
        private Func<T, bool> _predicate;

        public Condition(Func<T, bool> predicate)
        {
            this._predicate = predicate;
        }

        /// <summary>
        /// Applies argument to predicate function.
        /// </summary>
        /// <param name="obj"></param>
        /// <returns></returns>
        public bool Apply(object obj)
        {
            return _predicate((T)obj);
        }
    }
}
